home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / bcfamily / source / infoseg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-12  |  2.4 KB  |  102 lines

  1. //
  2. //      *******************************************************************
  3. //        JdeBP C++ Library Routines          General Public Licence v1.00
  4. //            Copyright (c) 1991,1992     Jonathan de Boyne Pollard
  5. //      *******************************************************************
  6. //
  7. // Part of FamAPI.LIB
  8. //
  9.  
  10. #include "famapi.h"
  11. #include "dosdos.h"
  12.  
  13. //
  14. //    Get the address of the "global" and "local" info segments
  15. //
  16. USHORT _APICALL
  17. DosGetInfoSeg    ( unsigned short far *PtrGSeg,
  18.                   unsigned short far *PtrLSeg )
  19. {
  20.     static USHORT GSeg = 0, LSeg = 0 ;
  21.  
  22.     GINFOSEG far *gi ;
  23.     LINFOSEG far *li ;
  24.  
  25.     if (GSeg == 0) {
  26.         USHORT err = DosAllocSeg((unsigned short) sizeof(GINFOSEG), &GSeg, 0) ;
  27.         if (err) return err ;
  28.  
  29.         gi = (GINFOSEG far *)MK_FP(GSeg, 0) ;
  30.  
  31.         gi->timezone = 0 ;
  32.         gi->cusecTimerInterval = 55 ;
  33.  
  34.         USHORT Version ;
  35.  
  36.         DosGetVersion( &Version ) ;
  37.  
  38.         gi->uchMinorVersion = Version & 0xff ;
  39.         gi->uchMajorVersion = Version >> 8 ;
  40.  
  41.         if (gi->uchMajorVersion >= 5) {
  42.             _AX = 0x3306 ;
  43.             Dos3Call() ;
  44.         } else
  45.             _DL = 0 ;
  46.  
  47.         gi->chRevisionLetter = _DL ;
  48.  
  49.         gi->sgCurrent = gi->sgMax = 1 ;    // Only one screen group.
  50.         gi->cHugeShift = 12 ;            // Hardcoded value !
  51.         gi->fProtectModeOnly = 0 ;        // Obviously, since we are in DOS.
  52.         DosDosQPSPSeg(&gi->pidForeground) ;
  53.         gi->fDynamicSched = 0 ;
  54.         gi->csecMaxWait = 1 ;
  55.         gi->cmsecMinSlice = gi->cmsecMaxSlice = 1 ;
  56.  
  57.         gi->bootdrive;
  58.  
  59.         // What about "UCHAR   amecRAS[32];" ?
  60.     }
  61.     if (LSeg == 0) {
  62.         USHORT err = DosAllocSeg((unsigned short) sizeof(LINFOSEG), &LSeg, 0) ;
  63.         if (err) return err ;
  64.  
  65.         li = (LINFOSEG far *)MK_FP(LSeg, 0) ;
  66.  
  67.         DosDosQPSPSeg(&li->pidCurrent) ;
  68.  
  69.         struct psp far *psp = (struct psp far *)MK_FP(li->pidCurrent, 0) ;
  70.  
  71.         li->pidParent = psp->parentpsp ;
  72.         li->prtyCurrent = 0 ;            // Unknown ?
  73.         li->tidCurrent = 1 ;            // Always the primary thread
  74.         li->sgCurrent = li->sgSub = 1 ;    // Always the single screen group
  75.         li->fForeground = 1 ;            // Always in the foreground
  76.     }
  77.  
  78.     //
  79.     //    Always update the current date and time on every call.
  80.     //
  81.     //    This does not set gi->time and gi->msecs !
  82.     //
  83.  
  84.     DOSDATETIME dt ;
  85.  
  86.     DosGetDateTime(&dt) ;
  87.  
  88.     gi->timezone = dt.timezone ;
  89.     gi->year = dt.year ;
  90.     gi->month = dt.month ;
  91.     gi->day = dt.day ;
  92.     gi->hour = dt.hours ;
  93.     gi->minutes = dt.minutes ;
  94.     gi->seconds = dt.seconds ;
  95.     gi->hundredths = dt.hundredths ;
  96.     gi->weekday = dt.weekday ;
  97.  
  98.     *PtrGSeg = GSeg ;
  99.     *PtrLSeg = LSeg ;
  100.  
  101.     return NO_ERROR ;
  102. }